package com.habdqn.studentmanager.bean;

import com.habdqn.studentmanager.exception.StudentException;

/**
 * @author Fan ip信息 2017年7月4日
 * 
 */
/**
 * @author Fan
 * 
 *         2017年7月4日
 * 
 */
public class IPInfo extends Bean{

	/**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
	 * 地址
	 */
	private String address;

	/**
	 * 端口号
	 */
	private int port;

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	/**
	 * 解析一串字符
	 * 
	 * @param str
	 * @return
	 */
	public static IPInfo getIPInfo(String str) {
		IPInfo info = new IPInfo();
		String[] arr = str.split(":");
		if (2 != arr.length) {
			throw new StudentException("IP地址错误");
		}
		
		info.address = arr[0];
		try{
			info.port = Integer.parseInt(arr[1]);
		}
		catch (NumberFormatException e) {
			throw new StudentException("IP地址错误");
		}
		
		return info;
	}
}
